/*
 * Copyright 2016-2019 yoara
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package yhao.infra.service.data.entitydiff.value;

import yhao.infra.service.data.entitydiff.BaseDiffParam;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * data-entityDiff数据对比传参数据结构类
 *
 * @author yoara
 */
public class DiffValueParam extends BaseDiffParam {
    private Map<String,DiffValueOperator> fieldMap = new HashMap<>();

    /**
     * 默认构造器
     */
    public DiffValueParam() {
    }

    /**
     * 对比给定的字段之构造器
     * @param fs
     */
    public DiffValueParam(Field[] fs) {
        for(Field f:fs){
            fieldMap.put(f.getName(),DiffValueOperator.DEFAULT_VALUE);
        }
    }

    /**
     * 增加新的字段极其映射行为
     * @param field 字段名
     * @param dvo 如果为null，则使用默认行为{@link DiffValueOperator#DEFAULT_VALUE}
     */
    public void putNewField(String field,DiffValueOperator dvo){
        fieldMap.put(field,dvo==null?DiffValueOperator.DEFAULT_VALUE:dvo);
    }

    public Map<String, DiffValueOperator> getFieldMap() {
        return fieldMap;
    }
}
